package com.syni.mdd.sjb.common.component.utils.common.utils.security;

import com.alibaba.fastjson.JSON;
import com.syni.mdd.sjb.common.component.utils.common.utils.CDNUtils;
import com.syni.mdd.sjb.common.component.utils.common.utils.ParamsMap;
import com.syni.mdd.sjb.common.component.utils.common.utils.WebUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @className InterfaceEncryUtil
 * @description TOO
 * @Author cfx
 * @DATE 2020/4/8 9:10
 * @VERSION 1.0
 **/
public class InterfaceEncryUtil {
    private static String apiKey = "apiMiDongDong0630@";
    public static ParamsMap getInterfaceEncry(ParamsMap paramsMap, String apiURL){
        String apiKey = "apiMiDongDong0630@";
        Map<String,Object> headerMap = new HashMap<>();
        //当前时间搓
        Integer timestamp = (int)(System.currentTimeMillis() / 1000);
        String t = String.format("%08X", timestamp).toLowerCase();
        //随机字符串
        String rs = CDNUtils.getStringRandom(8);
        //接口url
        String sign = WebUtils.MD5(apiKey + apiURL + t + rs).toLowerCase();
        Map<String,Object> AUTH = new HashMap();
        AUTH.put("sign",sign);
        AUTH.put("t",t);
        AUTH.put("rs",rs);
        paramsMap.put("AUTH", JSON.toJSONString(AUTH));
        return paramsMap;
    }

    public static String getInterfaceEncry(String apiURL){
        String apiKey = "apiMiDongDong0630@";
        Map<String,Object> headerMap = new HashMap<>();
        //当前时间搓
        Integer timestamp = (int)(System.currentTimeMillis() / 1000);
        String t = String.format("%08X", timestamp).toLowerCase();
        //随机字符串
        String rs = CDNUtils.getStringRandom(8);
        //接口url
        String sign = WebUtils.MD5(apiKey + apiURL + t + rs).toLowerCase();
        Map<String,Object> AUTH = new HashMap();
        AUTH.put("sign",sign);
        AUTH.put("t",t);
        AUTH.put("rs",rs);
        return JSON.toJSONString(AUTH);
    }


}
